class_name Player extends CharacterBody2D
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
enum Direction {
	LEFT = -1,
	RIGHT = +1
}
const SPEED = 120.0
const JUMP_VELOCITY = -300.0

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var isDead=false

func _ready():
	Main.player=self

func _physics_process(delta):
	if isDead:
		velocity.y += gravity * delta
		velocity.x=0
		move_and_slide()
		return
	var onFloor = is_on_floor()
	
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	var direction = Input.get_axis("ui_left", "ui_right")
	velocity.x = move_toward(velocity.x, direction * SPEED, SPEED)

	if !onFloor:
		velocity.y += gravity * delta
		sprite.play('jump')
	else:
		if direction:
			sprite.scale.x = direction
			sprite.play('run')
		else:
			sprite.play('idle')

	move_and_slide()
